package com.ejia.ui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.ejia.pojo.fytype;
import com.ejia.server.MtypeService;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Toolkit;

public class BJLX extends JFrame {

	private JPanel contentPane;
	private JTextField txtA;
	private JTextField txtA_1;
	private JTextField txtA_2;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					BJLX frame = new BJLX();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public BJLX() {
		setTitle("编辑类型");
		setIconImage(Toolkit.getDefaultToolkit().getImage(BJLX.class.getResource("/com/ejia/photo/客户管理系统.png")));
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 470, 698);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("费用名称");
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 24));
		lblNewLabel.setBounds(27, 61, 123, 24);
		contentPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("单价");
		lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 24));
		lblNewLabel_1.setBounds(27, 139, 123, 21);
		contentPane.add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("单位");
		lblNewLabel_2.setFont(new Font("宋体", Font.PLAIN, 24));
		lblNewLabel_2.setBounds(27, 223, 123, 21);
		contentPane.add(lblNewLabel_2);
		
		JLabel lblNewLabel_3 = new JLabel("类型详细");
		lblNewLabel_3.setFont(new Font("宋体", Font.PLAIN, 24));
		lblNewLabel_3.setBounds(27, 326, 123, 27);
		contentPane.add(lblNewLabel_3);
		
		
		SFLX.dataBind();
		
		txtA = new JTextField();
		txtA.setFont(new Font("宋体", Font.PLAIN, 24));
		txtA.setText(""+SFLX.fytypes.get(SFLX.index).getFyname());
		txtA.setBounds(177, 60, 242, 27);
		contentPane.add(txtA);
		txtA.setColumns(10);
		
		txtA_1 = new JTextField();
		txtA_1.setFont(new Font("宋体", Font.PLAIN, 24));
		txtA_1.setText(""+SFLX.fytypes.get(SFLX.index).getFyprice());
		txtA_1.setColumns(10);
		txtA_1.setBounds(177, 136, 242, 27);
		contentPane.add(txtA_1);
		
		txtA_2 = new JTextField();
		txtA_2.setFont(new Font("宋体", Font.PLAIN, 24));
		txtA_2.setText(""+SFLX.fytypes.get(SFLX.index).getUnit());
		txtA_2.setColumns(10);
		txtA_2.setBounds(177, 220, 242, 27);
		contentPane.add(txtA_2);
		
		JTextPane txtpnA = new JTextPane();
		txtpnA.setFont(new Font("宋体", Font.PLAIN, 24));
		txtpnA.setText(""+SFLX.fytypes.get(SFLX.index).getFydetail());
		txtpnA.setBounds(177, 326, 242, 168);
		contentPane.add(txtpnA);
		
		JButton button = new JButton("确定");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String name=txtA.getText();
				double price=Double.parseDouble(txtA_1.getText());
				String unit=txtA_2.getText();
				String detail=txtpnA.getText();
				if (MtypeService.update(name, price, unit, detail, SFLX.fytypes.get(SFLX.index).getFyid())) {
					JOptionPane.showMessageDialog(null, "修改成功");
					new SFLX().setVisible(true);
					dispose();
				} else {
					JOptionPane.showMessageDialog(null, "修改失败");
				}
				
			}
		});
		button.setFont(new Font("宋体", Font.PLAIN, 36));
		button.setBounds(67, 545, 123, 65);
		contentPane.add(button);
		
		JButton button_1 = new JButton("取消");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new SFLX().setVisible(true);
				dispose();
			}
		});
		button_1.setFont(new Font("宋体", Font.PLAIN, 36));
		button_1.setBounds(257, 545, 123, 65);
		contentPane.add(button_1);
		setLocationRelativeTo(null);
	}
}
